﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
    public class LoaiVeDAO
    {
        public List<LoaiVeDTO> Laydanhsachloaive()
        {
            List<LoaiVeDTO> ds_lvDto = new List<LoaiVeDTO>();
            try
            {
                string strSQL;
                SqlConnection cn;
                cn = DataProvider.ConnectDB();
                strSQL = "select * from LoaiVe";

                // Thuc thi chuoi sql
                SqlCommand cmd = new SqlCommand(strSQL, cn);

                SqlDataReader dr = cmd.ExecuteReader();


                while (dr.Read() == true)
                {
                    LoaiVeDTO lvdto = new LoaiVeDTO();
                    lvdto.MaLoai = dr.GetInt32(0);
                    lvdto.Ten = dr.GetString(1);
                    lvdto.ThoiGian = dr.GetString(2);
                    lvdto.Gia = Convert.ToDouble(dr.GetDecimal(3));


                    ds_lvDto.Add(lvdto);
                }
                cn.Close();
            }
            catch (Exception ex)
            {
                String e = ex.ToString(); 
            }

            return ds_lvDto;
        }
    }
}
